<?php
/**
 * 充值余额
**/
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='充值余额';
include_once './header.php';
?>
<style>
    .auth_color {
        background: linear-gradient(to left, #FF8A80, #FF5252);
        border-radius: 0.3rem;
        box-shadow: 1px 1px 9px 1px #eee;
    }
    .auth_color2 {
        background: linear-gradient(to left, #0091EA, #4FC3F7);
        border-radius: 0.3rem;
        box-shadow: 1px 1px 9px 1px #eee;
    }
    .auth_color3 {
        background: linear-gradient(to left, #5E35B1, #651FFF);
        border-radius: 0.3rem;
        box-shadow: 1px 1px 9px 1px #eee;
    }
</style>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                余额充值
            </div>
            <div class="card-body">
            <from class="layui-form">
            <?php
            if(!empty($conf['recharge_rebate_rule'])){
                $rules = explode(',',$conf['recharge_rebate_rule']);
                $i=1;
            ?>
            <div class="alert alert-success text-left">本平台回馈新老用户推出多充多返活动！<br/>
            <?php
            foreach($rules as $rule){
                $arr = explode('|',$rule);
                echo $i++.'.一次性充值 <font color="red"><strong>'.$arr[0].'</strong></font> 元以上，平台赠送您 <font color="red"><strong>'.$arr[1].'</strong>%</font> 的可消费余额<br/>';
            }
            ?>
            </div>
            <?php }?>
            <div class="text-center"><b>我当前的账户余额：<span style="font-size:16px; color:#FF6133;"><?php echo $userrow['rmb']?></span> 元</b></div><hr>
            <input type="text" class="form-control" name="value" autocomplete="off" placeholder="输入要充值的余额" lay-verType="tips" lay-verify="required">
            <br>
            <div class="layui-row layui-col-space12 text-center">
            <?php
            if($conf['alipay_api'])echo '<div class="layui-col-xs4"><button type="submit" class="layui-btn layui-btn-fluid auth_color3" lay-submit lay-filter="buy_alipay">支付宝</button></div>';
            if($conf['qqpay_api'])echo '<div class="layui-col-xs4"><button type="submit" class="layui-btn layui-btn-fluid auth_color2" lay-submit lay-filter="buy_qqpay">QQ钱包</button></div>';
            if($conf['wxpay_api'])echo '<div class="layui-col-xs4"><button type="submit" class="layui-btn layui-btn-fluid auth_color" lay-submit lay-filter="buy_wxpay">微信支付</button></div>';
            ?>
            </div>
            </form>
            <hr>
            <div class="text-center"><small style="color:red;">提示：最低充值金额<?php echo $conf['recharge_min'];?>元，最高充值金额<?php echo $conf['recharge_max'];?>元</small></div>
            </div>
        </div>

        <div class="card">
            <div class="card-header">
                充值记录
            </div>
            <div class="card-body">
                <div style="white-space:nowrap;overflow-x: auto;">
                    <table class="layui-table layuiadmin-page-table">
                        <thead><tr><th>充值金额</th><th>充值时间</th><th>状态</th></tr></thead>
                        <tbody>
                        <?php
                        $flag=false;
                        $rs=$DB->query("SELECT * FROM authguao_points WHERE uid='{$userrow['uid']}' AND action='充值' ORDER BY id DESC LIMIT 10");
                        while($res = $DB->fetch($rs))
                        {
                        $flag=true;
                        echo '<tr><td><b>'.$res['point'].'</b></td><td>'.$res['addtime'].'</td><td><font color="green">已完成</font></td></tr>';
                        }
                        if(!$flag)echo '<tr class="no-records-found"><td colspan="99">暂无充值记录</td></tr>';
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form', 'element'], function () {
    var form = layui.form;
    var element = layui.element;
    form.on('submit(buy_alipay)', function (data) {
        dopay('alipay');
        return false;
    });
    form.on('submit(buy_qqpay)', function (data) {
        dopay('qqpay');
        return false;
    });
    form.on('submit(buy_wxpay)', function (data) {
        dopay('wxpay');
        return false;
    });
    form.on('submit(usekm)', function (data) {
        usekm();
        return false;
    });
});
function dopay(type){
    var value=$("input[name='value']").val();
    if(value=='' || value==0){layer.msg('充值金额不能为空', {icon: 5});return false;}
    $.get("ajax.php?act=recharge&type="+type+"&value="+value, function(data) {
        if(data.code == 0){
            window.location.href='../other/submit.php?type='+type+'&orderid='+data.trade_no;
        }else{
            layer.msg(data.msg, {icon: 5});
        }
    }, 'json');
}
function usekm(){
    var km = $("input[name='km']").val();
    $.ajax({
        type : "POST",
        url : "ajax.php?act=usekm",
        data : {km:km},
        dataType : 'json',
        async: true,
        success : function(data) {
            if(data.code == 0){
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        }
    });
}
</script>